package com.shaoshaohuo.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.FarmOneRemark;
import com.shaoshaohuo.app.utils.CircleImageView;
import com.shaoshaohuo.app.utils.FiveCornerStar;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/7/3.
 */

public class FramOrderRemarkAdapter extends BaseAdapter {
    private Context context;
    private List<FarmOneRemark.DataBean> remark_data;

    public FramOrderRemarkAdapter(Context context, List<FarmOneRemark.DataBean> remark_data) {
        this.context = context;
        this.remark_data = remark_data;
    }

    public void refreshData(List<FarmOneRemark.DataBean> remark_data) {
        this.remark_data = remark_data;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return remark_data != null ? remark_data.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return remark_data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        FarmRemarkViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.farm_remark, parent, false);
            holder = new FarmRemarkViewHolder();
            holder.farm_remark_image = (CircleImageView) convertView.findViewById(R.id.farm_remark_image);

            holder.farm_remark_phone = (TextView) convertView.findViewById(R.id.farm_remark_phone);
            holder.farm_remark_hour = (TextView) convertView.findViewById(R.id.farm_remark_hour);
            holder.farm_remark_remark = (TextView) convertView.findViewById(R.id.farm_remark_remark);
            holder.farm_remark_xx = (FiveCornerStar) convertView.findViewById(R.id.farm_remark_xx);
            holder.farm_remark_shop_xx = (FiveCornerStar) convertView.findViewById(R.id.farm_remark_shop_xx);
            holder.farm_remark_shop_pic = (ImageView) convertView.findViewById(R.id.farm_remark_shop_pic);
            holder.farm_remark_shop_name = (TextView) convertView.findViewById(R.id.farm_remark_shop_name);
            holder.farm_remark_shop_address = (TextView) convertView.findViewById(R.id.farm_remark_shop_address);
            holder.farm_remark_shop_price = (TextView) convertView.findViewById(R.id.farm_remark_shop_price);
            convertView.setTag(holder);
        } else {
            holder = (FarmRemarkViewHolder) convertView.getTag();
        }
        Picasso.with(context).load(remark_data.get(position).getImg()).into(holder.farm_remark_shop_pic);
        holder.farm_remark_shop_name.setText(remark_data.get(position).getName());
        holder.farm_remark_shop_address.setText(remark_data.get(position).getCity());
        holder.farm_remark_shop_price.setText("￥" + remark_data.get(position).getAdult());
        holder.farm_remark_shop_xx.setdownnum(Float.parseFloat(remark_data.get(position).getLevel()));
        String phone = remark_data.get(position).getRemark().getAccount();
        String subString = phone.substring(3, 7);
        String phonea = phone.replace(subString, "****");
        holder.farm_remark_phone.setText(phonea);
        holder.farm_remark_xx.setdownnum(Float.valueOf(remark_data.get(position).getLevel()));
        holder.farm_remark_xx.setNum(5);
        holder.farm_remark_shop_xx.setdownnum(Float.valueOf(remark_data.get(position).getLevel()));
        holder.farm_remark_shop_xx.setIsdown(false);
        holder.farm_remark_shop_xx.setNum(5);
        holder.farm_remark_xx.setIsdown(false);
        holder.farm_remark_hour.setText(remark_data.get(position).getRemark().getTime());
        holder.farm_remark_remark.setText(remark_data.get(position).getRemark().getValue());
        Picasso.with(context).load(remark_data.get(position).getRemark().getHeadImg()).into(holder.farm_remark_image);
        holder.farm_remark_xx.setdownnum(Float.parseFloat(remark_data.get(position).getRemark().getLevel()));
        return convertView;
    }

    class FarmRemarkViewHolder {
        CircleImageView farm_remark_image;
        TextView farm_remark_phone, farm_remark_hour, farm_remark_remark;
        FiveCornerStar farm_remark_xx;
        ImageView farm_remark_shop_pic;
        TextView farm_remark_shop_name, farm_remark_shop_address, farm_remark_shop_price;
        FiveCornerStar farm_remark_shop_xx;
    }
}
